package com.hualan.web.fore;

import com.hualan.pojo.User;
import com.hualan.service.service.service.UserService;
import com.hualan.util.MD5Util;
import com.hualan.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")

public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public ResultEntity login(String nickname, String password){

        return ResultEntity.ok(userService.login(nickname, MD5Util.encode(password + nickname)));
    }
    @RequestMapping("/register")
    public ResultEntity register(@RequestBody User user){
        user.setPassword(MD5Util.encode(user.getPassword() + user.getNickname()));
        userService.register(user);
        return ResultEntity.ok("注册成功");
    }
    @RequestMapping("/findNickname")
    public ResultEntity findNickname(Integer uid){
        return ResultEntity.ok(userService.findNickname(uid));
    }
    @RequestMapping("/findPhone")
    public ResultEntity findPhone(Integer uid){
        return ResultEntity.ok(userService.findPhone(uid));
    }
    @RequestMapping("/updatePwd")
    public ResultEntity updatePwd(Integer uid, String oldPwd, String newPwd){
        return ResultEntity.ok(userService.updatePwd(uid, oldPwd, newPwd));
    }
    @RequestMapping("/updatePhone")
    public ResultEntity updatePhone(Integer uid, String phone){
        return ResultEntity.ok(userService.updatePhone(uid, phone));
    }

}
